<?php
/**
 * @author     ：lhw
 * @date       ：Created in 2019/8/4 20:05
 */

namespace app\api\controller;

use app\api\model\OrderMaster as OrderMasterModel;
use app\api\service\UserOrderService;
use app\api\Utils\ReturnUtils;

class PharmacyOrderController extends BaseController
{
    public function all($father_id){
        return ReturnUtils::TrueResult(OrderMasterModel::where(['father_pharmacy' => $father_id])->with(['useris'])->select());
    }

    public function one($order_id){
        return ReturnUtils::TrueResult(OrderMasterModel::where(['id' => $order_id])->with(['useris','detail','detail.drug','detail.drug.img','send'])->find());
    }

    public function son_all($son_id){
        return ReturnUtils::TrueResult(OrderMasterModel::where(['send_pharmacy' => $son_id])->with(['useris'])->select());
    }

    public function state($order_id,$state){
        OrderMasterModel::update(['state' => $state],['id'=>$order_id]);

        return ReturnUtils::TrueResult(null);
    }

    public function father_send($order_id,$send_pharmacy){
        OrderMasterModel::update(['send_pharmacy' => $send_pharmacy,'state' => 4],['id'=>$order_id]);
        return ReturnUtils::TrueResult(null);
    }

    public function son_send($order_id,$send_name,$send_phone){
        OrderMasterModel::update(['send_name' => $send_name,'send_phone' => $send_phone,'state' => 5],['id'=>$order_id]);
        return ReturnUtils::TrueResult(null);
    }
}